package jmu.cyxwcy.librarymanagement.controller;

import jmu.cyxwcy.librarymanagement.pojo.Result;
import jmu.cyxwcy.librarymanagement.pojo.User;
import jmu.cyxwcy.librarymanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Validated
public class UserController {
    @Autowired
    private UserService userService;
    //  用户
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user){
        userService.save(user);
        return Result.success();
    }

    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody User user){
        userService.updateById(user);
        return Result.success();
    }

    @DeleteMapping("/deleteUser/{userId}")
    public Result deleteUser(@PathVariable Integer userId){
        userService.removeById(userId);
        return Result.success();
    }
}
